#region " using "
using System;
using System.Data;
using System.Web.UI.WebControls;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Threading;
using System.Globalization;
using System.Text;
using System.IO;
using Smarty;
using Data;
#endregion

public partial class Csponsor_Search : AspNetRunnerPage
{
    int mypage = 1;
    int id = 1;
    string key;
    string templatefile = string.Empty;

    protected void Page_Init( object sender,  System.EventArgs e)  
    {
        strTableName = "sponsor";
        strTableNameLocale = "sponsor";
    }

    protected void Page_Load(object sender, EventArgs e)
    {
            // mandatory entry so compiler knows what table is processing
                        CheckSecurity();
            BuildForm();
            BuildBody();
            output.Append(func.BuildOutput(this, @"~\admin\sponsor_search.aspx", smarty));

            this.Response.Write(output.ToString());
            this.Response.End();
    }

    private string GetIncludes()
    {
        StringBuilder includes = new StringBuilder();
		includes.Append("<script language=\"JavaScript\" src=\"include/calendar.js\"></script>\r\n");
        includes.Append("<script language=\"JavaScript\" src=\"include/jsfunctions.js\"></script>\r\n");
        includes.Append("<script language=\"JavaScript\" src=\"include/jquery.js\"></script>\r\n");
        if (useAJAX) 
        {
            includes.Append("<script language=\"JavaScript\" src=\"include/onthefly.js\"></script>\r\n");
            includes.Append("<script language=\"JavaScript\" src=\"include/ajaxsuggest.js\"></script>\r\n");
        }
        includes.Append("<script language=\"JavaScript\" type=\"text/javascript\">\r\n");
        includes.Append("var locale_dateformat = '" + Control.locale_info("LOCALE_IDATE", smarty) + "';\r\n");
        includes.Append("var locale_datedelimiter = \"" + Control.locale_info("LOCALE_SDATE", smarty) + "\";\r\n");
        includes.Append("var bLoading=false;\r\n");
        includes.Append("var TEXT_PLEASE_SELECT='" + Control.AddSlashes("Please select") + "';\r\n");
        if (useAJAX) 
        {
            includes.Append("var SUGGEST_TABLE = \"sponsor_searchsuggest.aspx\";\r\n");
        }
	    includes.Append("var detect = navigator.userAgent.toLowerCase();");
        includes.Append("function checkIt(string)");
        includes.Append("{");
	    includes.Append("place = detect.indexOf(string) + 1;");
	    includes.Append("thestring = string;");
	    includes.Append("return place;");
        includes.Append("}");
        includes.Append("function ShowHideControls()");
        includes.Append("{");
	    includes.Append("document.getElementById('second_ID').style.display =  ");
		includes.Append("document.forms.editform.elements['asearchopt_ID'].value==\"Between\" ? '' : 'none'; ");
	    includes.Append("document.getElementById('second_FullName').style.display =  ");
		includes.Append("document.forms.editform.elements['asearchopt_FullName'].value==\"Between\" ? '' : 'none'; ");
	    includes.Append("document.getElementById('second_Email').style.display =  ");
		includes.Append("document.forms.editform.elements['asearchopt_Email'].value==\"Between\" ? '' : 'none'; ");
	    includes.Append("document.getElementById('second_Address').style.display =  ");
		includes.Append("document.forms.editform.elements['asearchopt_Address'].value==\"Between\" ? '' : 'none'; ");
	    includes.Append("document.getElementById('second_Phone').style.display =  ");
		includes.Append("document.forms.editform.elements['asearchopt_Phone'].value==\"Between\" ? '' : 'none'; ");
	    includes.Append("document.getElementById('second_Description').style.display =  ");
		includes.Append("document.forms.editform.elements['asearchopt_Description'].value==\"Between\" ? '' : 'none'; ");
	    includes.Append("document.getElementById('second_Viplevel').style.display =  ");
		includes.Append("document.forms.editform.elements['asearchopt_Viplevel'].value==\"Between\" ? '' : 'none'; ");
	    includes.Append("document.getElementById('second_Money').style.display =  ");
		includes.Append("document.forms.editform.elements['asearchopt_Money'].value==\"Between\" ? '' : 'none'; ");
	    includes.Append("document.getElementById('second_Active').style.display =  ");
		includes.Append("document.forms.editform.elements['asearchopt_Active'].value==\"Between\" ? '' : 'none'; ");
	    includes.Append("document.getElementById('second_CreatedDate').style.display =  ");
		includes.Append("document.forms.editform.elements['asearchopt_CreatedDate'].value==\"Between\" ? '' : 'none'; ");
	    includes.Append("return false;");
        includes.Append("}");
        includes.Append("function ResetControls()");
        includes.Append("{");
	    includes.Append("var i;");
	    includes.Append("e = document.forms[0].elements; ");
	    includes.Append("for (i=0;i<e.length;i++)"); 
	    includes.Append("{");
		includes.Append("if (e[i].name!='type' && e[i].className!='button' && e[i].type!='hidden')");
		includes.Append("{");
		includes.Append("if(e[i].type=='select-one')");
		includes.Append("e[i].selectedIndex=0;");
	    includes.Append("else if(e[i].type=='select-multiple')");
		includes.Append("{");
		includes.Append("var j;");
		includes.Append("for(j=0;j<e[i].options.length;j++)");
		includes.Append("e[i].options[j].selected=false;");
		includes.Append("}");
		includes.Append("else if(e[i].type=='checkbox' || e[i].type=='radio')");
		includes.Append("e[i].checked=false;");
	    includes.Append("else ");
		includes.Append("e[i].value = ''; ");
		includes.Append("}");
		includes.Append("else if(e[i].name.substr(0,6)=='value_' && e[i].type=='hidden')");
		includes.Append("e[i].value = ''; ");
	    includes.Append("}");
	    includes.Append("ShowHideControls();	");
	    includes.Append("return false;");
        includes.Append("}");

                includes.Append("$(document).ready(function() {");
	        includes.Append("document.forms.editform.value_ID.onkeyup=function(event) {searchSuggest(event,document.forms.editform.value_ID,'advanced')};");
	        includes.Append("document.forms.editform.value1_ID.onkeyup=function(event) {searchSuggest(event,document.forms.editform.value1_ID,'advanced1')};");
	        includes.Append("document.forms.editform.value_ID.onkeydown=function(event) {return listenEvent(event,document.forms.editform.value_ID,'advanced')};");
	        includes.Append("document.forms.editform.value1_ID.onkeydown=function(event) {return listenEvent(event,document.forms.editform.value1_ID,'advanced1')};");
	        includes.Append("document.forms.editform.value_FullName.onkeyup=function(event) {searchSuggest(event,document.forms.editform.value_FullName,'advanced')};");
	        includes.Append("document.forms.editform.value1_FullName.onkeyup=function(event) {searchSuggest(event,document.forms.editform.value1_FullName,'advanced1')};");
	        includes.Append("document.forms.editform.value_FullName.onkeydown=function(event) {return listenEvent(event,document.forms.editform.value_FullName,'advanced')};");
	        includes.Append("document.forms.editform.value1_FullName.onkeydown=function(event) {return listenEvent(event,document.forms.editform.value1_FullName,'advanced1')};");
	        includes.Append("document.forms.editform.value_Email.onkeyup=function(event) {searchSuggest(event,document.forms.editform.value_Email,'advanced')};");
	        includes.Append("document.forms.editform.value1_Email.onkeyup=function(event) {searchSuggest(event,document.forms.editform.value1_Email,'advanced1')};");
	        includes.Append("document.forms.editform.value_Email.onkeydown=function(event) {return listenEvent(event,document.forms.editform.value_Email,'advanced')};");
	        includes.Append("document.forms.editform.value1_Email.onkeydown=function(event) {return listenEvent(event,document.forms.editform.value1_Email,'advanced1')};");
	        includes.Append("document.forms.editform.value_Address.onkeyup=function(event) {searchSuggest(event,document.forms.editform.value_Address,'advanced')};");
	        includes.Append("document.forms.editform.value1_Address.onkeyup=function(event) {searchSuggest(event,document.forms.editform.value1_Address,'advanced1')};");
	        includes.Append("document.forms.editform.value_Address.onkeydown=function(event) {return listenEvent(event,document.forms.editform.value_Address,'advanced')};");
	        includes.Append("document.forms.editform.value1_Address.onkeydown=function(event) {return listenEvent(event,document.forms.editform.value1_Address,'advanced1')};");
	        includes.Append("document.forms.editform.value_Phone.onkeyup=function(event) {searchSuggest(event,document.forms.editform.value_Phone,'advanced')};");
	        includes.Append("document.forms.editform.value1_Phone.onkeyup=function(event) {searchSuggest(event,document.forms.editform.value1_Phone,'advanced1')};");
	        includes.Append("document.forms.editform.value_Phone.onkeydown=function(event) {return listenEvent(event,document.forms.editform.value_Phone,'advanced')};");
	        includes.Append("document.forms.editform.value1_Phone.onkeydown=function(event) {return listenEvent(event,document.forms.editform.value1_Phone,'advanced1')};");
	        includes.Append("document.forms.editform.value_Description.onkeyup=function(event) {searchSuggest(event,document.forms.editform.value_Description,'advanced')};");
	        includes.Append("document.forms.editform.value1_Description.onkeyup=function(event) {searchSuggest(event,document.forms.editform.value1_Description,'advanced1')};");
	        includes.Append("document.forms.editform.value_Description.onkeydown=function(event) {return listenEvent(event,document.forms.editform.value_Description,'advanced')};");
	        includes.Append("document.forms.editform.value1_Description.onkeydown=function(event) {return listenEvent(event,document.forms.editform.value1_Description,'advanced1')};");
	        includes.Append("document.forms.editform.value_Money.onkeyup=function(event) {searchSuggest(event,document.forms.editform.value_Money,'advanced')};");
	        includes.Append("document.forms.editform.value1_Money.onkeyup=function(event) {searchSuggest(event,document.forms.editform.value1_Money,'advanced1')};");
	        includes.Append("document.forms.editform.value_Money.onkeydown=function(event) {return listenEvent(event,document.forms.editform.value_Money,'advanced')};");
	        includes.Append("document.forms.editform.value1_Money.onkeydown=function(event) {return listenEvent(event,document.forms.editform.value1_Money,'advanced1')};");
        includes.Append("});");
        includes.Append("</script>");
        includes.Append("<div id=\"search_suggest\"></div>");

        return includes.ToString();
    }

    protected void BuildForm()
    {
        string all_checkbox="value=\"and\"";
        string any_checkbox="value=\"or\"";

        if(Asearchtype == "or")
        {
	        any_checkbox +=" checked";
        }
        else
        {
	        all_checkbox +=" checked";
        }
        smarty.Add("any_checkbox",any_checkbox);
        smarty.Add("all_checkbox",all_checkbox);

        IDictionary<string, string> editformats = new Dictionary<string, string>();
        string opt = "";
        bool not = false;
        string value = string.Empty;
        StringBuilder options = new StringBuilder();
        string searchtype = string.Empty;

        // ID 
        opt = "";
        not = false;
        value = string.Empty;
        searchtype = string.Empty;
        if(Search == 2)
        {
	        opt = Asearchopt["ID"];
	        not = Asearchnot["ID"];
	        value = Asearchfor["ID"];
        }

        Control control_ID = null;
        Control control1_ID = null;

        control_ID = new Control("ID", value, false, smarty, this.Request, builder, MODE.MODE_SEARCH);
        
        smarty.Add("ID_editcontrol", control_ID.BuildEditControl());
        control1_ID = new Control("ID", value, true, smarty, this.Request, builder, MODE.MODE_SEARCH);
                smarty.Add("ID_editcontrol1", control1_ID.BuildEditControl());

        IDictionary<string, string> ID_fieldblock = new Dictionary<string, string>();
	    ID_fieldblock["begin"] = "<input type=\"Hidden\" name=\"asearchfield[]\" value=\"ID\">";
	    ID_fieldblock["end"]=string.Empty;
	    smarty.Add("ID_fieldblock", ID_fieldblock);

        string ID_notbox="name=\"not_ID\"";
        if(not)
        {
	        ID_notbox +=" checked";
        }
        smarty.Add("ID_notbox",ID_notbox);

        //	write search options
        options = options.Remove(0, options.Length);
                options.Append("<OPTION VALUE=\"Contains\" " + ((opt=="Contains")?"selected":"") + ">" + "Contains" + "</option>");
        options.Append("<OPTION VALUE=\"Equals\" " + ((opt=="Equals")?"selected":"") + ">" + "Equals" + "</option>");
        options.Append("<OPTION VALUE=\"Starts with ...\" " + ((opt=="Starts with ...")?"selected":"") + ">" + "Starts with ..." + "</option>");
        options.Append("<OPTION VALUE=\"More than ...\" " + ((opt=="More than ...")?"selected":"") + ">" + "More than ..." + "</option>");
        options.Append("<OPTION VALUE=\"Less than ...\" " + ((opt=="Less than ...")?"selected":"") + ">" + "Less than ..." + "</option>");
        options.Append("<OPTION VALUE=\"Equal or more than ...\" " + ((opt=="Equal or more than ...")?"selected":"") + ">" + "Equal or more than ..." + "</option>");
        options.Append("<OPTION VALUE=\"Equal or less than ...\" " + ((opt=="Equal or less than ...")?"selected":"") + ">" + "Equal or less than ..." + "</option>");
        options.Append("<OPTION VALUE=\"Between\" " + ((opt=="Between")?"selected":"") + ">" + "Between" + "</option>");
        options.Append("<OPTION VALUE=\"Empty\" " + ((opt=="Empty")?"selected":"") + ">" + "Empty" + "</option>");
        searchtype = "<SELECT ID=\"SearchOption\" NAME=\"asearchopt_ID\" SIZE=1 onChange=\"return ShowHideControls();\">";
        searchtype += options.ToString();
        searchtype += "</SELECT>";
        smarty.Add("searchtype_ID", searchtype);
        //	edit format
                editformats["ID"] = "Text field";
        // FullName 
        opt = "";
        not = false;
        value = string.Empty;
        searchtype = string.Empty;
        if(Search == 2)
        {
	        opt = Asearchopt["FullName"];
	        not = Asearchnot["FullName"];
	        value = Asearchfor["FullName"];
        }

        Control control_FullName = null;
        Control control1_FullName = null;

        control_FullName = new Control("FullName", value, false, smarty, this.Request, builder, MODE.MODE_SEARCH);
        
        smarty.Add("FullName_editcontrol", control_FullName.BuildEditControl());
        control1_FullName = new Control("FullName", value, true, smarty, this.Request, builder, MODE.MODE_SEARCH);
                smarty.Add("FullName_editcontrol1", control1_FullName.BuildEditControl());

        IDictionary<string, string> FullName_fieldblock = new Dictionary<string, string>();
	    FullName_fieldblock["begin"] = "<input type=\"Hidden\" name=\"asearchfield[]\" value=\"FullName\">";
	    FullName_fieldblock["end"]=string.Empty;
	    smarty.Add("FullName_fieldblock", FullName_fieldblock);

        string FullName_notbox="name=\"not_FullName\"";
        if(not)
        {
	        FullName_notbox +=" checked";
        }
        smarty.Add("FullName_notbox",FullName_notbox);

        //	write search options
        options = options.Remove(0, options.Length);
                options.Append("<OPTION VALUE=\"Contains\" " + ((opt=="Contains")?"selected":"") + ">" + "Contains" + "</option>");
        options.Append("<OPTION VALUE=\"Equals\" " + ((opt=="Equals")?"selected":"") + ">" + "Equals" + "</option>");
        options.Append("<OPTION VALUE=\"Starts with ...\" " + ((opt=="Starts with ...")?"selected":"") + ">" + "Starts with ..." + "</option>");
        options.Append("<OPTION VALUE=\"More than ...\" " + ((opt=="More than ...")?"selected":"") + ">" + "More than ..." + "</option>");
        options.Append("<OPTION VALUE=\"Less than ...\" " + ((opt=="Less than ...")?"selected":"") + ">" + "Less than ..." + "</option>");
        options.Append("<OPTION VALUE=\"Equal or more than ...\" " + ((opt=="Equal or more than ...")?"selected":"") + ">" + "Equal or more than ..." + "</option>");
        options.Append("<OPTION VALUE=\"Equal or less than ...\" " + ((opt=="Equal or less than ...")?"selected":"") + ">" + "Equal or less than ..." + "</option>");
        options.Append("<OPTION VALUE=\"Between\" " + ((opt=="Between")?"selected":"") + ">" + "Between" + "</option>");
        options.Append("<OPTION VALUE=\"Empty\" " + ((opt=="Empty")?"selected":"") + ">" + "Empty" + "</option>");
        searchtype = "<SELECT ID=\"SearchOption\" NAME=\"asearchopt_FullName\" SIZE=1 onChange=\"return ShowHideControls();\">";
        searchtype += options.ToString();
        searchtype += "</SELECT>";
        smarty.Add("searchtype_FullName", searchtype);
        //	edit format
                editformats["FullName"] = "Text field";
        // Email 
        opt = "";
        not = false;
        value = string.Empty;
        searchtype = string.Empty;
        if(Search == 2)
        {
	        opt = Asearchopt["Email"];
	        not = Asearchnot["Email"];
	        value = Asearchfor["Email"];
        }

        Control control_Email = null;
        Control control1_Email = null;

        control_Email = new Control("Email", value, false, smarty, this.Request, builder, MODE.MODE_SEARCH);
        
        smarty.Add("Email_editcontrol", control_Email.BuildEditControl());
        control1_Email = new Control("Email", value, true, smarty, this.Request, builder, MODE.MODE_SEARCH);
                smarty.Add("Email_editcontrol1", control1_Email.BuildEditControl());

        IDictionary<string, string> Email_fieldblock = new Dictionary<string, string>();
	    Email_fieldblock["begin"] = "<input type=\"Hidden\" name=\"asearchfield[]\" value=\"Email\">";
	    Email_fieldblock["end"]=string.Empty;
	    smarty.Add("Email_fieldblock", Email_fieldblock);

        string Email_notbox="name=\"not_Email\"";
        if(not)
        {
	        Email_notbox +=" checked";
        }
        smarty.Add("Email_notbox",Email_notbox);

        //	write search options
        options = options.Remove(0, options.Length);
                options.Append("<OPTION VALUE=\"Contains\" " + ((opt=="Contains")?"selected":"") + ">" + "Contains" + "</option>");
        options.Append("<OPTION VALUE=\"Equals\" " + ((opt=="Equals")?"selected":"") + ">" + "Equals" + "</option>");
        options.Append("<OPTION VALUE=\"Starts with ...\" " + ((opt=="Starts with ...")?"selected":"") + ">" + "Starts with ..." + "</option>");
        options.Append("<OPTION VALUE=\"More than ...\" " + ((opt=="More than ...")?"selected":"") + ">" + "More than ..." + "</option>");
        options.Append("<OPTION VALUE=\"Less than ...\" " + ((opt=="Less than ...")?"selected":"") + ">" + "Less than ..." + "</option>");
        options.Append("<OPTION VALUE=\"Equal or more than ...\" " + ((opt=="Equal or more than ...")?"selected":"") + ">" + "Equal or more than ..." + "</option>");
        options.Append("<OPTION VALUE=\"Equal or less than ...\" " + ((opt=="Equal or less than ...")?"selected":"") + ">" + "Equal or less than ..." + "</option>");
        options.Append("<OPTION VALUE=\"Between\" " + ((opt=="Between")?"selected":"") + ">" + "Between" + "</option>");
        options.Append("<OPTION VALUE=\"Empty\" " + ((opt=="Empty")?"selected":"") + ">" + "Empty" + "</option>");
        searchtype = "<SELECT ID=\"SearchOption\" NAME=\"asearchopt_Email\" SIZE=1 onChange=\"return ShowHideControls();\">";
        searchtype += options.ToString();
        searchtype += "</SELECT>";
        smarty.Add("searchtype_Email", searchtype);
        //	edit format
                editformats["Email"] = "Text field";
        // Address 
        opt = "";
        not = false;
        value = string.Empty;
        searchtype = string.Empty;
        if(Search == 2)
        {
	        opt = Asearchopt["Address"];
	        not = Asearchnot["Address"];
	        value = Asearchfor["Address"];
        }

        Control control_Address = null;
        Control control1_Address = null;

        control_Address = new Control("Address", value, false, smarty, this.Request, builder, MODE.MODE_SEARCH);
        
        smarty.Add("Address_editcontrol", control_Address.BuildEditControl());
        control1_Address = new Control("Address", value, true, smarty, this.Request, builder, MODE.MODE_SEARCH);
                smarty.Add("Address_editcontrol1", control1_Address.BuildEditControl());

        IDictionary<string, string> Address_fieldblock = new Dictionary<string, string>();
	    Address_fieldblock["begin"] = "<input type=\"Hidden\" name=\"asearchfield[]\" value=\"Address\">";
	    Address_fieldblock["end"]=string.Empty;
	    smarty.Add("Address_fieldblock", Address_fieldblock);

        string Address_notbox="name=\"not_Address\"";
        if(not)
        {
	        Address_notbox +=" checked";
        }
        smarty.Add("Address_notbox",Address_notbox);

        //	write search options
        options = options.Remove(0, options.Length);
                options.Append("<OPTION VALUE=\"Contains\" " + ((opt=="Contains")?"selected":"") + ">" + "Contains" + "</option>");
        options.Append("<OPTION VALUE=\"Equals\" " + ((opt=="Equals")?"selected":"") + ">" + "Equals" + "</option>");
        options.Append("<OPTION VALUE=\"Starts with ...\" " + ((opt=="Starts with ...")?"selected":"") + ">" + "Starts with ..." + "</option>");
        options.Append("<OPTION VALUE=\"More than ...\" " + ((opt=="More than ...")?"selected":"") + ">" + "More than ..." + "</option>");
        options.Append("<OPTION VALUE=\"Less than ...\" " + ((opt=="Less than ...")?"selected":"") + ">" + "Less than ..." + "</option>");
        options.Append("<OPTION VALUE=\"Equal or more than ...\" " + ((opt=="Equal or more than ...")?"selected":"") + ">" + "Equal or more than ..." + "</option>");
        options.Append("<OPTION VALUE=\"Equal or less than ...\" " + ((opt=="Equal or less than ...")?"selected":"") + ">" + "Equal or less than ..." + "</option>");
        options.Append("<OPTION VALUE=\"Between\" " + ((opt=="Between")?"selected":"") + ">" + "Between" + "</option>");
        options.Append("<OPTION VALUE=\"Empty\" " + ((opt=="Empty")?"selected":"") + ">" + "Empty" + "</option>");
        searchtype = "<SELECT ID=\"SearchOption\" NAME=\"asearchopt_Address\" SIZE=1 onChange=\"return ShowHideControls();\">";
        searchtype += options.ToString();
        searchtype += "</SELECT>";
        smarty.Add("searchtype_Address", searchtype);
        //	edit format
                editformats["Address"] = "Text field";
        // Phone 
        opt = "";
        not = false;
        value = string.Empty;
        searchtype = string.Empty;
        if(Search == 2)
        {
	        opt = Asearchopt["Phone"];
	        not = Asearchnot["Phone"];
	        value = Asearchfor["Phone"];
        }

        Control control_Phone = null;
        Control control1_Phone = null;

        control_Phone = new Control("Phone", value, false, smarty, this.Request, builder, MODE.MODE_SEARCH);
        
        smarty.Add("Phone_editcontrol", control_Phone.BuildEditControl());
        control1_Phone = new Control("Phone", value, true, smarty, this.Request, builder, MODE.MODE_SEARCH);
                smarty.Add("Phone_editcontrol1", control1_Phone.BuildEditControl());

        IDictionary<string, string> Phone_fieldblock = new Dictionary<string, string>();
	    Phone_fieldblock["begin"] = "<input type=\"Hidden\" name=\"asearchfield[]\" value=\"Phone\">";
	    Phone_fieldblock["end"]=string.Empty;
	    smarty.Add("Phone_fieldblock", Phone_fieldblock);

        string Phone_notbox="name=\"not_Phone\"";
        if(not)
        {
	        Phone_notbox +=" checked";
        }
        smarty.Add("Phone_notbox",Phone_notbox);

        //	write search options
        options = options.Remove(0, options.Length);
                options.Append("<OPTION VALUE=\"Contains\" " + ((opt=="Contains")?"selected":"") + ">" + "Contains" + "</option>");
        options.Append("<OPTION VALUE=\"Equals\" " + ((opt=="Equals")?"selected":"") + ">" + "Equals" + "</option>");
        options.Append("<OPTION VALUE=\"Starts with ...\" " + ((opt=="Starts with ...")?"selected":"") + ">" + "Starts with ..." + "</option>");
        options.Append("<OPTION VALUE=\"More than ...\" " + ((opt=="More than ...")?"selected":"") + ">" + "More than ..." + "</option>");
        options.Append("<OPTION VALUE=\"Less than ...\" " + ((opt=="Less than ...")?"selected":"") + ">" + "Less than ..." + "</option>");
        options.Append("<OPTION VALUE=\"Equal or more than ...\" " + ((opt=="Equal or more than ...")?"selected":"") + ">" + "Equal or more than ..." + "</option>");
        options.Append("<OPTION VALUE=\"Equal or less than ...\" " + ((opt=="Equal or less than ...")?"selected":"") + ">" + "Equal or less than ..." + "</option>");
        options.Append("<OPTION VALUE=\"Between\" " + ((opt=="Between")?"selected":"") + ">" + "Between" + "</option>");
        options.Append("<OPTION VALUE=\"Empty\" " + ((opt=="Empty")?"selected":"") + ">" + "Empty" + "</option>");
        searchtype = "<SELECT ID=\"SearchOption\" NAME=\"asearchopt_Phone\" SIZE=1 onChange=\"return ShowHideControls();\">";
        searchtype += options.ToString();
        searchtype += "</SELECT>";
        smarty.Add("searchtype_Phone", searchtype);
        //	edit format
                editformats["Phone"] = "Text field";
        // Description 
        opt = "";
        not = false;
        value = string.Empty;
        searchtype = string.Empty;
        if(Search == 2)
        {
	        opt = Asearchopt["Description"];
	        not = Asearchnot["Description"];
	        value = Asearchfor["Description"];
        }

        Control control_Description = null;
        Control control1_Description = null;

        control_Description = new Control("Description", value, false, smarty, this.Request, builder, MODE.MODE_SEARCH);
        
        smarty.Add("Description_editcontrol", control_Description.BuildEditControl());
        control1_Description = new Control("Description", value, true, smarty, this.Request, builder, MODE.MODE_SEARCH);
                smarty.Add("Description_editcontrol1", control1_Description.BuildEditControl());

        IDictionary<string, string> Description_fieldblock = new Dictionary<string, string>();
	    Description_fieldblock["begin"] = "<input type=\"Hidden\" name=\"asearchfield[]\" value=\"Description\">";
	    Description_fieldblock["end"]=string.Empty;
	    smarty.Add("Description_fieldblock", Description_fieldblock);

        string Description_notbox="name=\"not_Description\"";
        if(not)
        {
	        Description_notbox +=" checked";
        }
        smarty.Add("Description_notbox",Description_notbox);

        //	write search options
        options = options.Remove(0, options.Length);
                options.Append("<OPTION VALUE=\"Contains\" " + ((opt=="Contains")?"selected":"") + ">" + "Contains" + "</option>");
        options.Append("<OPTION VALUE=\"Equals\" " + ((opt=="Equals")?"selected":"") + ">" + "Equals" + "</option>");
        options.Append("<OPTION VALUE=\"Starts with ...\" " + ((opt=="Starts with ...")?"selected":"") + ">" + "Starts with ..." + "</option>");
        options.Append("<OPTION VALUE=\"More than ...\" " + ((opt=="More than ...")?"selected":"") + ">" + "More than ..." + "</option>");
        options.Append("<OPTION VALUE=\"Less than ...\" " + ((opt=="Less than ...")?"selected":"") + ">" + "Less than ..." + "</option>");
        options.Append("<OPTION VALUE=\"Equal or more than ...\" " + ((opt=="Equal or more than ...")?"selected":"") + ">" + "Equal or more than ..." + "</option>");
        options.Append("<OPTION VALUE=\"Equal or less than ...\" " + ((opt=="Equal or less than ...")?"selected":"") + ">" + "Equal or less than ..." + "</option>");
        options.Append("<OPTION VALUE=\"Between\" " + ((opt=="Between")?"selected":"") + ">" + "Between" + "</option>");
        options.Append("<OPTION VALUE=\"Empty\" " + ((opt=="Empty")?"selected":"") + ">" + "Empty" + "</option>");
        searchtype = "<SELECT ID=\"SearchOption\" NAME=\"asearchopt_Description\" SIZE=1 onChange=\"return ShowHideControls();\">";
        searchtype += options.ToString();
        searchtype += "</SELECT>";
        smarty.Add("searchtype_Description", searchtype);
        //	edit format
                editformats["Description"] = "Text field";
        // Viplevel 
        opt = "";
        not = false;
        value = string.Empty;
        searchtype = string.Empty;
        if(Search == 2)
        {
	        opt = Asearchopt["Viplevel"];
	        not = Asearchnot["Viplevel"];
	        value = Asearchfor["Viplevel"];
        }

        Control control_Viplevel = null;
        Control control1_Viplevel = null;

        control_Viplevel = new Control("Viplevel", value, false, smarty, this.Request, builder, MODE.MODE_SEARCH);
        
        smarty.Add("Viplevel_editcontrol", control_Viplevel.BuildEditControl());
        control1_Viplevel = new Control("Viplevel", value, true, smarty, this.Request, builder, MODE.MODE_SEARCH);
                smarty.Add("Viplevel_editcontrol1", control1_Viplevel.BuildEditControl());

        IDictionary<string, string> Viplevel_fieldblock = new Dictionary<string, string>();
	    Viplevel_fieldblock["begin"] = "<input type=\"Hidden\" name=\"asearchfield[]\" value=\"Viplevel\">";
	    Viplevel_fieldblock["end"]=string.Empty;
	    smarty.Add("Viplevel_fieldblock", Viplevel_fieldblock);

        string Viplevel_notbox="name=\"not_Viplevel\"";
        if(not)
        {
	        Viplevel_notbox +=" checked";
        }
        smarty.Add("Viplevel_notbox",Viplevel_notbox);

        //	write search options
        options = options.Remove(0, options.Length);
                options.Append("<OPTION VALUE=\"Equals\" " + ((opt=="Equals")?"selected":"") + ">" + "Equals" + "</option>");
        searchtype = "<SELECT ID=\"SearchOption\" NAME=\"asearchopt_Viplevel\" SIZE=1 onChange=\"return ShowHideControls();\">";
        searchtype += options.ToString();
        searchtype += "</SELECT>";
        smarty.Add("searchtype_Viplevel", searchtype);
        //	edit format
                editformats["Viplevel"] = "Lookup wizard";
        // Money 
        opt = "";
        not = false;
        value = string.Empty;
        searchtype = string.Empty;
        if(Search == 2)
        {
	        opt = Asearchopt["Money"];
	        not = Asearchnot["Money"];
	        value = Asearchfor["Money"];
        }

        Control control_Money = null;
        Control control1_Money = null;

        control_Money = new Control("Money", value, false, smarty, this.Request, builder, MODE.MODE_SEARCH);
        
        smarty.Add("Money_editcontrol", control_Money.BuildEditControl());
        control1_Money = new Control("Money", value, true, smarty, this.Request, builder, MODE.MODE_SEARCH);
                smarty.Add("Money_editcontrol1", control1_Money.BuildEditControl());

        IDictionary<string, string> Money_fieldblock = new Dictionary<string, string>();
	    Money_fieldblock["begin"] = "<input type=\"Hidden\" name=\"asearchfield[]\" value=\"Money\">";
	    Money_fieldblock["end"]=string.Empty;
	    smarty.Add("Money_fieldblock", Money_fieldblock);

        string Money_notbox="name=\"not_Money\"";
        if(not)
        {
	        Money_notbox +=" checked";
        }
        smarty.Add("Money_notbox",Money_notbox);

        //	write search options
        options = options.Remove(0, options.Length);
                options.Append("<OPTION VALUE=\"Contains\" " + ((opt=="Contains")?"selected":"") + ">" + "Contains" + "</option>");
        options.Append("<OPTION VALUE=\"Equals\" " + ((opt=="Equals")?"selected":"") + ">" + "Equals" + "</option>");
        options.Append("<OPTION VALUE=\"Starts with ...\" " + ((opt=="Starts with ...")?"selected":"") + ">" + "Starts with ..." + "</option>");
        options.Append("<OPTION VALUE=\"More than ...\" " + ((opt=="More than ...")?"selected":"") + ">" + "More than ..." + "</option>");
        options.Append("<OPTION VALUE=\"Less than ...\" " + ((opt=="Less than ...")?"selected":"") + ">" + "Less than ..." + "</option>");
        options.Append("<OPTION VALUE=\"Equal or more than ...\" " + ((opt=="Equal or more than ...")?"selected":"") + ">" + "Equal or more than ..." + "</option>");
        options.Append("<OPTION VALUE=\"Equal or less than ...\" " + ((opt=="Equal or less than ...")?"selected":"") + ">" + "Equal or less than ..." + "</option>");
        options.Append("<OPTION VALUE=\"Between\" " + ((opt=="Between")?"selected":"") + ">" + "Between" + "</option>");
        options.Append("<OPTION VALUE=\"Empty\" " + ((opt=="Empty")?"selected":"") + ">" + "Empty" + "</option>");
        searchtype = "<SELECT ID=\"SearchOption\" NAME=\"asearchopt_Money\" SIZE=1 onChange=\"return ShowHideControls();\">";
        searchtype += options.ToString();
        searchtype += "</SELECT>";
        smarty.Add("searchtype_Money", searchtype);
        //	edit format
                editformats["Money"] = "Text field";
        // Active 
        opt = "";
        not = false;
        value = string.Empty;
        searchtype = string.Empty;
        if(Search == 2)
        {
	        opt = Asearchopt["Active"];
	        not = Asearchnot["Active"];
	        value = Asearchfor["Active"];
        }

        Control control_Active = null;
        Control control1_Active = null;

        control_Active = new Control("Active", value, false, smarty, this.Request, builder, MODE.MODE_SEARCH);
        
        smarty.Add("Active_editcontrol", control_Active.BuildEditControl());
        control1_Active = new Control("Active", value, true, smarty, this.Request, builder, MODE.MODE_SEARCH);
                smarty.Add("Active_editcontrol1", control1_Active.BuildEditControl());

        IDictionary<string, string> Active_fieldblock = new Dictionary<string, string>();
	    Active_fieldblock["begin"] = "<input type=\"Hidden\" name=\"asearchfield[]\" value=\"Active\">";
	    Active_fieldblock["end"]=string.Empty;
	    smarty.Add("Active_fieldblock", Active_fieldblock);

        string Active_notbox="name=\"not_Active\"";
        if(not)
        {
	        Active_notbox +=" checked";
        }
        smarty.Add("Active_notbox",Active_notbox);

        //	write search options
        options = options.Remove(0, options.Length);
                options.Append("<OPTION VALUE=\"Equals\" " + ((opt=="Equals")?"selected":"") + ">" + "Equals" + "</option>");
        searchtype = "<SELECT ID=\"SearchOption\" NAME=\"asearchopt_Active\" SIZE=1 onChange=\"return ShowHideControls();\">";
        searchtype += options.ToString();
        searchtype += "</SELECT>";
        smarty.Add("searchtype_Active", searchtype);
        //	edit format
                editformats["Active"] = "Lookup wizard";
        // CreatedDate 
        opt = "";
        not = false;
        value = string.Empty;
        searchtype = string.Empty;
        if(Search == 2)
        {
	        opt = Asearchopt["CreatedDate"];
	        not = Asearchnot["CreatedDate"];
	        value = Asearchfor["CreatedDate"];
        }

        Control control_CreatedDate = null;
        Control control1_CreatedDate = null;

        control_CreatedDate = new Control("CreatedDate", value, false, smarty, this.Request, builder, MODE.MODE_SEARCH);
        
        smarty.Add("CreatedDate_editcontrol", control_CreatedDate.BuildEditControl());
        control1_CreatedDate = new Control("CreatedDate", value, true, smarty, this.Request, builder, MODE.MODE_SEARCH);
                smarty.Add("CreatedDate_editcontrol1", control1_CreatedDate.BuildEditControl());

        IDictionary<string, string> CreatedDate_fieldblock = new Dictionary<string, string>();
	    CreatedDate_fieldblock["begin"] = "<input type=\"Hidden\" name=\"asearchfield[]\" value=\"CreatedDate\">";
	    CreatedDate_fieldblock["end"]=string.Empty;
	    smarty.Add("CreatedDate_fieldblock", CreatedDate_fieldblock);

        string CreatedDate_notbox="name=\"not_CreatedDate\"";
        if(not)
        {
	        CreatedDate_notbox +=" checked";
        }
        smarty.Add("CreatedDate_notbox",CreatedDate_notbox);

        //	write search options
        options = options.Remove(0, options.Length);
                options.Append("<OPTION VALUE=\"Equals\" " + ((opt=="Equals")?"selected":"") + ">" + "Equals" + "</option>");
        options.Append("<OPTION VALUE=\"More than ...\" " + ((opt=="More than ...")?"selected":"") + ">" + "More than ..." + "</option>");
        options.Append("<OPTION VALUE=\"Less than ...\" " + ((opt=="Less than ...")?"selected":"") + ">" + "Less than ..." + "</option>");
        options.Append("<OPTION VALUE=\"Equal or more than ...\" " + ((opt=="Equal or more than ...")?"selected":"") + ">" + "Equal or more than ..." + "</option>");
        options.Append("<OPTION VALUE=\"Equal or less than ...\" " + ((opt=="Equal or less than ...")?"selected":"") + ">" + "Equal or less than ..." + "</option>");
        options.Append("<OPTION VALUE=\"Between\" " + ((opt=="Between")?"selected":"") + ">" + "Between" + "</option>");
        options.Append("<OPTION VALUE=\"Empty\" " + ((opt=="Empty")?"selected":"") + ">" + "Empty" + "</option>");
        searchtype = "<SELECT ID=\"SearchOption\" NAME=\"asearchopt_CreatedDate\" SIZE=1 onChange=\"return ShowHideControls();\">";
        searchtype += options.ToString();
        searchtype += "</SELECT>";
        smarty.Add("searchtype_CreatedDate", searchtype);
        //	edit format
                editformats["CreatedDate"] = "Date";
    }

    protected void BuildBody()
    {
        string linkdata="";

        linkdata += "<script type=\"text/javascript\">\r\n";
        object value = null;
        if(Asearchfor.ContainsKey(""))
        {
            value = Asearchfor[""] ;
        }
        object fvalue = null;
        if(Asearchfor.ContainsKey("ArtID"))
        {
            fvalue = Asearchfor["ArtID"];
        }

        if (useAJAX) 
        {
            Smarty.Table tableInfo = null;
            Smarty.Field fieldInfo = null;
            List<Smarty.LookupField> lookups = null;
            string txt = ""; 

        }
        else
        {
        }
        linkdata += "</script>\r\n";


        IDictionary<string, object> body = new Dictionary<string, object>();
        body["begin"] = GetIncludes();
        body["end"] = linkdata + "<script>ShowHideControls()</script>";
        smarty.Add("body", body);

        IDictionary<string, object> contents_block = new Dictionary<string, object>();
        contents_block["begin"]="<form method=\"POST\"";
                contents_block["begin"] += "action=\"sponsor_list.aspx\"" ;
        contents_block["begin"] += "name=\"editform\"><input type=\"hidden\" id=\"a\" name=\"a\" value=\"advsearch\">";
        contents_block["end"] ="</form>";
        smarty.Add("contents_block",contents_block);

        smarty.Add("searchbutton_attrs","name=\"SearchButton\" onclick=\"javascript:document.forms.editform.submit();\"");
        smarty.Add("resetbutton_attrs","onclick=\"return ResetControls();\"");
        smarty.Add("backbutton_attrs","onclick=\"javascript: document.forms.editform.a.value='return'; document.forms.editform.submit();\"");
        smarty.Add("conditions_block",true);
        smarty.Add("search_button",true);
        smarty.Add("reset_button",true);
        smarty.Add("back_button",true);
    }

        private bool CheckSecurity()
    {
        if(string.IsNullOrEmpty(UserName))
        { 
            MyUrl = this.Request.AppRelativeCurrentExecutionFilePath;
            this.Server.Transfer("~/admin/login.aspx?message=expired");
	        return false;
        }
                if(!BaseCheckSecurity(OwnerID, "Search"))
        {
                }
        return true;
    }

    private string Asearchtype
    {
        get
        {
            return (string)SessionPropertyGet("type", string.Empty);
        }
        set
        {
            SessionPropertySet("type", value);
        }
    }
    
    private int Search
    {
        get
        {
            return (int)SessionPropertyGet(strTableName + "_search", -1);
        }
        set
        {
            SessionPropertySet(strTableName + "_search", value);
        }
    }

    private IDictionary<string, string> Asearchopt
    {
        get
        {
            return (IDictionary<string, string>)SessionPropertyGet(strTableName + "_asearchopt", new Dictionary<string, string>());
        }
        set
        {
            SessionPropertySet(strTableName + "_asearchopt", value);
        }
    }

    private IDictionary<string, bool> Asearchnot
    {
        get
        {
            return (IDictionary<string, bool>)SessionPropertyGet(strTableName + "_asearchnot", new Dictionary<string, bool>());
        }
        set
        {
            SessionPropertySet(strTableName + "_asearchnot", value);
        }
    }

    private IDictionary<string, string> Asearchfor
    {
        get
        {
            return (IDictionary<string, string>)SessionPropertyGet(strTableName + "_asearchfor", new Dictionary<string, string>());
        }
        set
        {
            SessionPropertySet(strTableName + "_asearchfor", value);
        }
    }

    private string Mastertable
    {
        get
        {
            return (string)SessionPropertyGet(strTableName + "_mastertable", string.Empty);
        }
        set
        {
            SessionPropertySet(strTableName + "_mastertable", value);
        }
    }
}
